<?php
	if($_POST['ilosc'] != 0)
	{
		$conection = mysql_connect($mysql_host,$mysql_user,$mysql_password);
		mysql_set_charset('utf8',$conection);
		@mysql_select_db($mysql_database) or die("Nie udalo sie wybrac bazy danych");
		
		for($i=0;$i < $_POST['ilosc']; $i++)
		{
			if($_POST["answer".$i] == "")
				continue;
			if($_POST["answer".$i] == "dodaj")
			{
				//$query = "UPDATE  NEWS` SET ILOSC_KOM=ILOSC_KOM+1 WHERE ID = ".$_POST["id_n".$i];
				$query2 = "UPDATE `KOM_G` SET ACCESS = 1 WHERE ID =".$_POST["id".$i];
				//mysql_query($query);
				//if(mysql_error())
				//	die(mysql_error());
				mysql_query($query2);
				if(mysql_error())
					die(mysql_error());
				
			}
			else
			{
				$query = "DELETE FROM `KOM_G` WHERE ID =".$_POST["id".$i];
				mysql_query($query);
				if(mysql_error())
					die(mysql_error());
			}
			
		}
		mysql_close();
		echo "Wykonano pomyslnie :)";
	}
	else
	{
		$conection = mysql_connect($mysql_host,$mysql_user,$mysql_password);
		mysql_set_charset('utf8',$conection);
		@mysql_select_db($mysql_database) or die("Nie udalo sie wybrac bazy danych");
		$query = "SELECT * FROM `KOM_G` WHERE `ACCESS`= '0'";
		
		$result = mysql_query($query);
		
		if(mysql_error())
			die(mysql_error());	
			
		$ilosc = mysql_num_rows($result);
		if($ilosc == 0)
			die("Nie ma żadnych komentarzy do zatwierdzenia.");
		
		echo "<form method=\"post\"><input type=\"hidden\" name=\"ilosc\" value=\"".mysql_num_rows($result)."\"/>";
		
		for($i=0; $i < $ilosc; $i++)
		{
			$row = mysql_fetch_assoc($result);
			
			$date = date_create($row['DATE']); 
			echo "<strong>".$row['NAME']."</strong> ".date_format($date,"Y-m-d H:i:s")."<br/>".
				$row['TEXT']."<br/>";
					
			echo 
				"<input type=\"hidden\" name=\"id".$i."\" value=\"".$row['ID']."\" />
				<input type=\"hidden\" name=\"id_n".$i."\" value=\"".$row['ID_N']."\" />
				<input type=\"radio\" name=\"answer".$i."\" value=\"dodaj\" />Dodaj
				<input type=\"radio\" name=\"answer".$i."\" value=\"usun\" />Usuń<br/><br/>";

		}
		
		echo "<input  type=\"submit\" value=\"Wykonaj\" /></form><br/>";
	}
?>